package com.xxw.yygh.order.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.xxw.yygh.common.result.R;
import com.xxw.yygh.common.utils.JwtHelper;
import com.xxw.yygh.enums.OrderStatusEnum;
import com.xxw.yygh.model.order.OrderInfo;
import com.xxw.yygh.order.service.OrderInfoService;
import com.xxw.yygh.vo.order.OrderCountQueryVo;
import com.xxw.yygh.vo.order.OrderQueryVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 订单表(OrderInfo)表控制层
 *
 * @author makejava
 * @since 2023-03-07 14:37:06
 */
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController{

    @Resource
    private OrderInfoService orderInfoService;

    //生成订单
    @PostMapping("/{scheduleId}/{patientId}")
    public R submitOrder(@PathVariable String scheduleId,
                         @PathVariable Long patientId){
        Long orderId = orderInfoService.submitOrder(scheduleId,patientId);
        return R.ok().data("orderId",orderId);
    }

    //带查询分页
    @GetMapping("/{pageNum}/{pageSize}")
    public R getOrderInfoPage(@PathVariable Integer pageNum,
                              @PathVariable Integer pageSize,
                              OrderQueryVo orderQueryVo,
                              @RequestHeader String token){
        Long userId = JwtHelper.getUserId(token);
        //只查询当前用户下的订单信息
        orderQueryVo.setUserId(userId);
        Page<OrderInfo> page=orderInfoService.getOrderInfoPage(pageNum,pageSize,orderQueryVo);
        return R.ok().data("page",page);
    }

    //订单状态
    @GetMapping("/list")
    public R getOrderList(){
        List<Map<String, Object>> statusList = OrderStatusEnum.getStatusList();
        return R.ok().data("list",statusList);
    }

    //订单详情
    @GetMapping("/{orderId}")
    public R detail(@PathVariable Long orderId){
        OrderInfo orderInfo = orderInfoService.detail(orderId);
        return R.ok().data("orderInfo",orderInfo);
    }

    //取消预约
    @GetMapping("/cancel/{orderId}")
    public R cancelOrder(@PathVariable Long orderId){
        orderInfoService.cancelOrder(orderId);
        return R.ok();
    }

    //远程调用：统计
    @PostMapping("/statistics")
    public Map<String,Object> statistics(@RequestBody OrderCountQueryVo orderCountQueryVo){
        return orderInfoService.statistics(orderCountQueryVo);
    }

}

